package com.example.happiness.task;
import com.example.happiness.constant.Message;
import com.example.happiness.mapper.ChatMapper;
import com.example.happiness.mapper.OrderMapper;
import com.example.happiness.pojo.Chat;
import com.example.happiness.pojo.Order;
import com.example.happiness.pojo.generalDTO.OrderStateDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

@Component
@Slf4j
public class ChatTask {

    @Autowired
    ChatMapper chatMapper;

    @Scheduled(cron = "0 * * * * ? ")
    public void processTimeOutOrder(){
        log.info("定时处理聊天记录订单：{}", LocalDateTime.now());
        List<Chat> chatList = chatMapper.selectChatList();
        if(chatList != null && chatList.size() > 0){
            for(Chat chat : chatList){
                Duration duration = Duration.between(chat.getTime(),LocalDateTime.now());
                long hours = duration.toHours();
                if(hours >= 24){
                    chatMapper.deleteByPrimaryKey(chat.getId());
                }
            }
        }
    }
}
